package com.caiyi.financial.nirvana.sms.server;

import java.util.ArrayList;
import java.util.List;

public class ClientMsgIdEntity {

    private String clientMsgId;
    private List<Long> messageIdLst;

    public ClientMsgIdEntity(String msgId) {
        this.clientMsgId = msgId;
        this.messageIdLst = new ArrayList<Long>();
    }

    public void addMsgId(Long msgId) {
        this.messageIdLst.add(msgId);
    }

    public String getClientMsgId() {
        return clientMsgId;
    }

    public List<Long> getMessageIdLst() {
        return messageIdLst;
    }

    public String toRedisStr() {
        StringBuffer stb = new StringBuffer();
        stb.append(clientMsgId);
        for (Long msgId : messageIdLst) {
            stb.append(",").append(msgId);
        }
        return stb.toString();
    }

    public static ClientMsgIdEntity redisStr2Entity(String redisStr) {
        if (null == redisStr) {
            return null;
        }
        String[] strArr = redisStr.split(",");
        if (strArr.length < 2) {
            return null;
        }
        String clientMsgId = strArr[0];
        ClientMsgIdEntity entity = new ClientMsgIdEntity(clientMsgId);
        for (int i = 1; i < strArr.length; i++) {
            entity.addMsgId(Long.parseLong(strArr[i]));
        }
        return entity;
    }
}
